<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>JSSpec results</title>
<link rel="stylesheet" type="text/css" href="../JSSpec/JSSpec.css" />
<script type="text/javascript" src="../JSSpec/diff_match_patch.js"></script>
<script type="text/javascript" src="../JSSpec/JSSpec.js"></script>
<script type="text/javascript" src="../amok.js"></script>    
<script type="text/javascript">// <![CDATA[

/**
 * As an amok user
 * I want a smooth DSL
 * So that I can easily read and remember the syntax
 */

function Mokee(){
    _foo = "foo";
    this.getFoo = function(){
        return _foo;
    };
};

describe('Scenario 1: method added to the mock', {
	'before_each': function(){
        mock = amok.mock(Mokee);
	},
	'Given that amok is available as a namespace': function() {
        value_of(typeof amok).should_be("object")
	},
    'And I have a mock object': function(){
        value_of(typeof mock).should_be("object");
    },
    'And mock does not have a method called getFoo': function(){
        value_of( mock.getFoo ).should_be_undefined();
    },
    'And mock does not have a method called getFoo': function(){
        value_of( mock.getBar ).should_be_undefined();
    },    
    'When I pass the name of a method within my mokee to mock.should_receive then my mock should also have that method': function() {
        mock.should_receive("getFoo");
        value_of( typeof mock.getFoo ).should_be( "function" );
	},
    'When I pass the name of a second method within my mokee to mock.should_receive then my mock should also have that second method': function() {
        mock.should_receive("getFoo");
        mock.should_receive("getBar");
        value_of( typeof mock.getFoo ).should_be( "function" );
        value_of( typeof mock.getBar ).should_be( "function" );
    }
});

describe('Scenario 2: Set expectation of arguments passed to mock method', {
	'before_each': function(){
        mock = amok.mock(Mokee);
        mock.should_receive("getFoo");
    },
	'Given that amok is available as a namespace': function() {
        value_of(typeof amok).should_be("object")
	},
    'And I have a mock object': function(){
        value_of(typeof mock).should_be("object");
    },
    'And mock has a method called getFoo': function(){
        value_of( typeof mock.getFoo ).should_be('function');
    },
    'When I pass arguments of the wrong value to with_args then an exception will be thrown': function() {
        mock.with_args("test1", "test2");
        value_of( function(){ mock.getFoo("test1", "test2"); } ).should_not_throw();
        value_of( function(){ mock.getFoo("wrong", "arguments"); } ).should_throw();
	},
    'When I pass arguments of the wrong type to with_args then an exception will be thrown': function() {
        mock.with_args(String, Number);
        value_of( function(){ mock.getFoo("test1", 999); } ).should_not_throw();
        value_of( function(){ mock.getFoo("test1", "string"); } ).should_throw();
    }
});

describe('Scenario 3: Set expectation of return value', {
	'before_each': function(){
        mock = amok.mock(Mokee);
        mock.should_receive("getFoo");
    },
	'Given that amok is available as a namespace': function() {
        value_of(typeof amok).should_be("object")
	},
    'And I have a mock object': function(){
        value_of(typeof mock).should_be("object");
    },
    'And mock has a method called getFoo': function(){
        value_of( typeof mock.getFoo ).should_be('function');
    },
    'And getFoo has no return value': function(){
        value_of( mock.getFoo() ).should_be_undefined();
    },	
    'When I pass an argument to and_return, that value will be returned when the mock method is called': function() {
        mock.and_return("some value");
        value_of( mock.getFoo() ).should_be("some value");
	}
});

describe('Scenario 4: Set expectation of callback to be triggered by mock method call', {
	'before_each': function(){
        mock = amok.mock(Mokee);
        mock.should_receive("getFoo");
    },
	'Given that amok is available as a namespace': function() {
        value_of(typeof amok).should_be("object")
	},
    'And I have a mock object': function(){
        value_of(typeof mock).should_be("object");
    },
    'And mock has a method called getFoo': function(){
        value_of( typeof mock.getFoo ).should_be('function');
    },
    'When I pass a callback and and array of arguments to and_callback, the callback will be called with those arguments': function() {
		var one = null;
		var two = null;

		var callback = function(msg){
			one = msg;
		}
        mock.and_callback(callback, "one");

		mock.getFoo()
        value_of( one ).should_be("one");
	}
});

describe('Scenario 5: Override constructors', {
	'before_each': function(){
		Foo = function(){
			this.getFoo = function(){
				return "foo";
			}
		};
		
		mock = new amok.mock(Foo);
		mock.should_receive('getFoo').and_return('bar');
		Foo = amok.mock_all_with(mock);
	},
	'constructor should return mock object': function(){
		value_of(new Foo().getFoo()).should_be("bar");
	}
});


// ]]></script>
</head>
<body><div style="display:none;"><p>A</p><p>B</p></div></body>
</html>
